import http from '@/utils/http'
import type { BrandRes, BrandForm, CategoryModel, AttrModel, ProductRes } from './type'

export class ProductApi {
  // 品牌列表
  static brandList = (page: number, limit: number) =>
    http.get<BrandRes>(`/admin/product/baseTrademark/${page}/${limit}`)

  // 品牌编辑
  static brandEdit = (param: BrandForm) => {
    return param.id
      ? http.put<string>('/admin/product/baseTrademark/update', param)
      : http.post('/admin/product/baseTrademark/save', param)
  }

  // 品牌删除
  static brandDelete = (id: number) => http.delete(`/admin/product/baseTrademark/remove/${id}`)

  // 分类三级联动
  static getCategoryList1 = () => http.get<CategoryModel[]>('/admin/product/getCategory1')
  static getCategoryList2 = (c1: number | string) => http.get<CategoryModel[]>(`/admin/product/getCategory2/${c1}`)
  static getCategoryList3 = (c2: number | string) => http.get<CategoryModel[]>(`/admin/product/getCategory3/${c2}`)

  // 属性
  static getAttrList = (c1: number | string, c2: number | string, c3: number | string) =>
    http.get<AttrModel[]>(`/admin/product/attrInfoList/${c1}/${c2}/${c3}`)
  static editAttr = (param: AttrModel) => http.post('/admin/product/saveAttrInfo', param)
  static deleteAttr = (id: number | string) => http.delete('/admin/product/deleteAttr/' + id)

  // spu
  static getProductList = (page: number, limit: number, c3: number | string) =>
    http.get<ProductRes>(`/admin/product/${page}/${limit}?category3Id=${c3}`)
}
